package com.yozinga.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.yozinga.R;
import com.yozinga.entity.Offers;
import com.yozinga.util.ImageLoader;

public class OffersAdapter  extends BaseAdapter{

	ArrayList<Offers> cList;
	ArrayList<String> lList;
	ImageLoader mImageLoder;
	Context mContext;

	public OffersAdapter(ArrayList<Offers> offersList,ArrayList<String> logoList,Context context) {
		cList = offersList;
		lList = logoList;
		mContext = context;
		mImageLoder =new ImageLoader(mContext);
	}

	@Override
	public int getCount() {
		return cList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	public class ViewHolder{

		public TextView dealName;
		public TextView dealDesc;
		public RatingBar ratingbar;
		public ImageView mLogo;
	}

	@Override
	public View getView(int position, View v, ViewGroup arg2) {
		ViewHolder holder ;

		if (v == null) {
			holder = new ViewHolder();
			LayoutInflater inflater = LayoutInflater.from(mContext);
			v = inflater.inflate(R.layout.adapter_offer_listitems,null);
			holder.mLogo =(ImageView)v.findViewById(R.id.ivLogo);
			holder.dealName = (TextView) v.findViewById(R.id.tvMName);
			holder.dealDesc = (TextView) v.findViewById(R.id.tvMTag);
			holder.ratingbar = (RatingBar) v.findViewById(R.id.rbRating);

			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}  

		final Offers bean = cList.get(position);

		holder.dealName.setText(bean.getDealName());
		holder.dealDesc.setText(bean.getDealDesc());
		//if(bean.getRating()!=null)
		//holder.ratingbar.setRating(Float.parseFloat(bean.getRating()));
		mImageLoder.DisplayImage(lList.get(position), holder.mLogo,mContext);
		return v;
	}
}